﻿using System;
using System.Windows.Data;

namespace HobSoft.SoccerBet2014.Common.Wpf.Converter
{
    public class BooleanConverter : IValueConverter
    {
        public object True { get; set; }
        public object False { get; set; }
        public object Default { get; set; }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (True == null)
                throw new ArgumentNullException("True", "need True result");
            if (False == null)
                throw new ArgumentNullException("False", "need False result");
            if (Default == null)
                throw new ArgumentNullException("Default", "need Default result");

            if (value is bool)
            {
                var boolValue = (bool)value;
                return boolValue ? True : False;
            }

            var nullBool = value as Nullable<bool>;
            if (nullBool == null)
                return Default;
            return nullBool.Value ? True : False;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


}
